package com.books.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.books.model.entity.order.BuyOrder;
import com.books.model.tool.MonthPriceTool;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ZhouRui
 * @title: 码上就来
 * @projectName cbstore-spring-boot
 * @description: TODO
 * @date 2021/10/1114:05
 */
@Mapper
public interface BuyOrderMapper extends BaseMapper<BuyOrder> {
    @Select("select * from buy_order where user_id=#{userId} order by buy_time desc")
    List<BuyOrder> findAllOrder(Integer userId);

    @Select("select * from buy_order where buy_id=#{buyId}")
    BuyOrder findOneOrder(String buyId);

    @Select("select * from buy_order order by buy_time desc")
    List<BuyOrder> getAllOrders();

    @Select("SELECT DATE_FORMAT( buy_time, '%Y-%m' ) AS buy_month , sum(total_money) AS month_price FROM buy_order GROUP BY buy_month ORDER BY MAX(buy_time) DESC")
    List<MonthPriceTool> getMonthMoney();
}
